package thread;

import java.util.Scanner;

public class Demo16 {
    public static void main(String[] args) throws InterruptedException {
        Object locker = new Object();
        Thread t1 = new Thread(()->{
            try {
                System.out.println("wait之前");
                synchronized (locker){
                    locker.wait();
                }
                System.out.println("wait之后");
            }catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        Thread t2 = new Thread(()->{
            Scanner scanner = new Scanner(System.in);
            //next是一个带阻塞的效果，等待IO进入的阻塞
            System.out.println("输入任意内容，通知唤醒t1:");
            scanner.next();
            synchronized (locker){
                //先wait，再notify
                locker.notify();
            }
        });
        t1.start();
        t2.start();
    }
}
